/// @Classname : HcTextButton
/// @Author :
/// @Time : 2023-11-09 14:17
/// @Description : 文字按钮 无边框 无颜色

import 'package:flutter/material.dart';
import 'package:hc_ui/config/hc_customer_config.dart';
import 'package:hc_ui/theme/hc_common_theme.dart';

import 'package:hc_ui/widget/button/hc_base_button.dart';

EdgeInsets? _cPadding = const EdgeInsets.symmetric(vertical: 8, horizontal: 8);
double _cSplashOpacity = 0.12;
double _cHighlightOpacity = 0.04;

class HcTextButton extends StatelessWidget {
  final String text;
  final bool disabled;
  final Color? textColor;
  final double? fontSize;
  final EdgeInsets? padding;
  final Color? splashColor;
  final Color? highlightColor;
  final TextStyle? textStyle;
  final FontWeight? fontWeight;
  final Color? disableTextColor;
  final VoidCallback? onPressed;
  final Color? disabledTextColor;
  final Size? minSize;
  final Size? maxSize;
  final int? maxLines;
  final bool loading;
  final VoidCallback? longPress;
  final Widget? child;

  /// 文字按钮
  /// [text] 文字
  /// [child]子组件优先级大于文字
  /// [textColor] 文字颜色
  /// [disabledTextColor] 文字禁用颜色
  /// [fontSize]文字大小
  /// [fontWeight]文字粗细
  /// [padding]内边距
  /// [textStyle] 文字样式
  const HcTextButton({
    super.key,
    required this.onPressed,
    this.disabled = false,
    required this.text,
    this.textColor,
    this.disableTextColor,
    this.fontWeight,
    this.fontSize,
    this.padding,
    this.textStyle,
    this.splashColor,
    this.highlightColor,
    this.disabledTextColor,
    this.minSize,
    this.maxSize,
    this.maxLines,
    this.loading = false,
    this.longPress,
    this.child,
  });

  const HcTextButton.icon({
    super.key,
    required this.onPressed,
    this.disabled = false,
    this.textColor,
    this.disableTextColor,
    this.fontWeight,
    this.fontSize,
    this.padding,
    this.textStyle,
    this.splashColor,
    this.highlightColor,
    this.disabledTextColor,
    Size? minSize,
    this.maxSize,
    this.maxLines,
    this.loading = false,
    this.longPress,
    required this.child,
  })  : text = '',
        minSize = minSize ?? Size.zero;

  @override
  Widget build(BuildContext context) {
    HcCommonTheme theme = HcCustomerConfig().allTheme.commonTheme;
    return HcBaseButton.text(
      minSize: minSize ?? const Size(64, 36),
      maxSize: maxSize,
      loading: loading,
      onPressed: onPressed,
      longPress: longPress,
      maxLines: maxLines,
      padding: padding ?? _cPadding,
      disabled: disabled,
      textStyle: textStyle,
      fontWeight: fontWeight,
      fontSize: fontSize,
      textColor: textColor ?? theme.primaryColor,
      disabledTextColor:
          disabledTextColor ?? theme.primaryColor.withOpacity(0.12),
      splashColor:
          splashColor ?? theme.primaryColor.withOpacity(_cSplashOpacity),
      highlightColor:
          highlightColor ?? theme.primaryColor.withOpacity(_cHighlightOpacity),
      text: text,
      child: child,
    );
  }
}
